<?php
echo $this->Html->css('jquery.password');
echo $this->Html->script('jquery.password');
?>
<div class="users form">
    <?php echo $this->Form->create('User'); ?>
    <fieldset>
        <legend><?php echo __('Add YP'); ?></legend>
        <?php
        echo $this->Form->input('username');
        ?>
        <div class="feedback">
            <div id="username"></div>
        </div>
        <?php
        echo $this->Form->input('password');
        echo $this->Form->input('confirm_password', array('type' => 'password'));
        ?>
        <div class="feedback">
            <div id="strongy"></div>
            <div id="match"></div>
        </div>
        <?php
        echo $this->Form->input('email');
        ?>
        <div class="feedback">
            <div id="email"></div>
        </div>
        <?php
        echo $this->Form->input('first_name');
        echo $this->Form->input('middle_name');
        echo $this->Form->input('last_name');
        echo $this->Form->input('aka_first_name');
        echo $this->Form->input('aka_last_name');
        echo $this->Form->input('dob', array('type' => 'date','label'=>'DOB'));
        echo $this->Form->input('phone_1');
        echo $this->Form->input('phone_2');
        echo $this->Form->input('marital_status_id');
        echo $this->Form->input('gender_id');
        echo $this->Form->input('ethincity_id');
        echo $this->Form->input('alternate_contact');
        ?>
        <div class="hidden" id="alternat-info">
            <?php
            echo $this->Form->input('alternate_phone');
            echo $this->Form->input('carrier_id');
            ?>
        </div>
        <?php
        echo $this->Form->input('ca_resident',array('options'=>array('0'=>'No','1'=>'Yes'),'type' => 'radio', 'legend'=>'CA Resident'));
        echo $this->Form->input('role_id', array('type' => 'hidden', 'value' => 3));
        echo $this->Form->input('active', array('type' => 'hidden', 'value' => 1));
        echo $this->Form->input('is_union_member', array('type' => 'hidden', 'value' => $_SESSION['is_union_member']));
        ?>
    </fieldset>
    <?php echo $this->Form->end(__('Next')); ?>
</div>
<script>
    $(function() {
        $('#UserPassword').password({
            minLength: 4,
            strengthIndicator: $('#strongy'),
            doubleType: $('#UserConfirmPassword'),
        });
    });
    $().ready(function() {
        $('#UserPassword').keyup(function() {
            if ($('#UserPassword').val() == $('#UserConfirmPassword').val()) {
                $("#match").text('Passwords Match');
            } else {
                $("#match").text('Passwords don\'t Match');
            }
        });
        $('#UserConfirmPassword').keyup(function() {
            if ($('#UserPassword').val() == $('#UserConfirmPassword').val()) {
                $("#match").text('Passwords Match');
            } else {
                $("#match").text('Passwords don\'t Match');
            }
        });

        //checking user name 
        $("#UserUsername").keyup(function() {
            if ($(this).val().length > 3) {
                $.ajax({url: "<?php echo $this->Html->url(array('controller' => 'users', 'action' => 'available', 'username', 'em' => false)); ?>/" + $(this).val(), success: function(result) {
                        $("#username").html(result);
                    }});
            }
        });
        $("#UserEmail").keyup(function() {
            var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
            if ($(this).val().match(mailformat)) {
                $.ajax({url: "<?php echo $this->Html->url(array('controller' => 'users', 'action' => 'available', 'email', 'em' => false)); ?>/" + $(this).val(), success: function(result) {
                        $("#email").html(result);
                    }});
            } else {
                $("#email").html("Invalide Email Address");
            }

        });

        $("#UserAlternateContact").change(function() {

            if ($(this).is(':checked')) {
                $("#alternat-info").css('display', 'block');
            } else {
                $("#alternat-info").css('display', 'none');
            }
        });
        
        $("#UserPhone1, #UserPhone2, #UserAlternatePhone").mask("(999) 999-9999");
    });
</script>